﻿using System.Linq.Extensions;
using System.Linq.PageList;
using Dyao.Book.Contract;
using Dyao.Book.Entity;
using Dyao.Book.Repository.Abstractions;

namespace Dyao.Book.Repository
{
    using Foundation.Replacement;

    public class OperationLogRepository : DataRepository<OperationLogEntity>, IOperationLogRepository
    {
        /// <inheritdoc cref="IOperationLogRepository.BulkInsertAsync"/>
        public new Task BulkInsertAsync(IEnumerable<OperationLogEntity> entities, CancellationToken cancellationToken)
        {
            return base.BulkInsertAsync(entities, cancellationToken);
        }

        /// <inheritdoc cref="IOperationLogRepository.GetPageListAsync"/>
        public async Task<IPageList<OperationLogEntity>> GetPageListAsync(IPageFilter<OperationLogFilterDto> pageFilter, CancellationToken cancellationToken = default)
        {
            var filter = pageFilter.Filter ?? new OperationLogFilterDto();
            var query = this.GetQueryable()
                .Where(b => b.SourceId == filter.SourceId)
                .OrderOrThenBy(x => x.ID, false)
                .AsNoTracking();

            return await query.ToPageListAsync(pageFilter, cancellationToken);
        }
    }
}
